package me.zhengjie.sqlservice.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import me.zhengjie.mapper.WcsChainLineConfigMapper;
import me.zhengjie.pojo.entity.WcsChainLineConfig;
import me.zhengjie.sqlservice.WcsChainLineConfigService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class WcsChainLineConfigServiceImpl extends ServiceImpl<WcsChainLineConfigMapper,WcsChainLineConfig> implements WcsChainLineConfigService {
    private final WcsChainLineConfigMapper wcsChainLineConfigMapper;

    @Override
    public List<WcsChainLineConfig> selectAll() {
       return wcsChainLineConfigMapper.selectList(null);
    }

    @Override
    public WcsChainLineConfig selectTransportStorage(String transportStorage) {
        LambdaQueryWrapper<WcsChainLineConfig> wcsChainLineConfigLambdaQueryWrapper = new LambdaQueryWrapper<>();
        wcsChainLineConfigLambdaQueryWrapper.eq(WcsChainLineConfig::getTransportStorage, transportStorage);
        return wcsChainLineConfigMapper.selectOne(wcsChainLineConfigLambdaQueryWrapper);
    }

    @Override
    public boolean updateOneReturnResultReturn(Integer oneReturnResult, int oneReturn) {
        LambdaUpdateWrapper<WcsChainLineConfig> wcsChainLineConfigLambdaUpdateChainWrapper = new LambdaUpdateWrapper<>();
        wcsChainLineConfigLambdaUpdateChainWrapper.set(WcsChainLineConfig::getOneWritePlc,oneReturn)
                .eq(WcsChainLineConfig::getOneAddress,oneReturnResult);
        return wcsChainLineConfigMapper.update(null,wcsChainLineConfigLambdaUpdateChainWrapper) >0;
    }

    @Override
    public boolean updateTwoReturnResultReturn(Integer twoAddress, int twoReturn) {
        LambdaUpdateWrapper<WcsChainLineConfig> wcsChainLineConfigLambdaUpdateChainWrapper = new LambdaUpdateWrapper<>();
        wcsChainLineConfigLambdaUpdateChainWrapper.set(WcsChainLineConfig::getTwoWritePlc,twoReturn)
                .eq(WcsChainLineConfig::getTwoAddress,twoAddress);
        return wcsChainLineConfigMapper.update(null,wcsChainLineConfigLambdaUpdateChainWrapper) >0;
    }
}
